import worker, { MessageEvents } from '@ohos.worker';

const workPort = worker.workerPort;

workPort.onmessage = (message: MessageEvents): void => {
  let data = message.data;
  switch (data) {
    case "close": {
      console.log("worker: close");
      workPort.close();
      break;
    }
    case "doJob": {
      workPort.postMessage('jobFinish');
      break;
    }
    default : {
      break;
    }
  }
}

workPort.onerror = () => {
  console.log("Work thread on error");
}